/* name: bishop
 * author: 5ab
 * created at: 2024-06-13
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;

signed main()
{
	freopen("bishop.in", "r", stdin);
	freopen("bishop.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m;
	bool rv = 0;
	
	cin >> n >> m;
	if (n > m)
		swap(n, m), rv = 1;
	
	vector<pair<int, int>> ans;
	if (n == m)
	{
		if (n == 1)
			ans.emplace_back(0, 0);
		else
		{
			for (int i = 1; i < n; i++)
			{
				ans.emplace_back(0, i);
				ans.emplace_back(n - 1, i);
			}
		}
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			ans.emplace_back(i, 0);
			ans.emplace_back(i, m - 1);
		}
		int i = n;
		for (; i < m - n; i += n)
			for (int j = 0; j < n; j++)
				ans.emplace_back(j, i);
		i -= n;
		if (n & 1)
		{
			int d = n / 2 + 1;
			for (int j = i + d; j < m - d; j++)
				ans.emplace_back(n / 2, j);
		}
		else
		{
			int d = (m - 1 - i - n) / 2;
			for (int j = n / 2 - d; j < n / 2 + d; j++)
				ans.emplace_back(j, (i + (m - 1)) / 2);
		}
	}
	cout << ssz(ans) << "\n";
	for (auto [x, y] : ans)
	{
		if (rv) swap(x, y);
		cout << x + 1 << " " << y + 1 << "\n";
	}
	
	return 0;
}
// started coding at: 06-13 08:49:40